package tsinghua.smxq.mc;

import android.app.Application;
import android.util.Log;
import android.widget.Toast;

import com.baidu.mapapi.BMapManager;
import com.baidu.mapapi.MKEvent;
import com.baidu.mapapi.MKGeneralListener;

public class BaiduMap extends Application {
	static BaiduMap bMapApp;

	BMapManager bMapMan = null;

	String myKey = "F7CBD0EFF200C1288878817C7821BD40CFD09089";

	boolean bKeyRight = true;

	public void onCreate() {
		bMapApp = this;
		bMapMan = new BMapManager(this);
		bMapMan.init(this.myKey, new MyGeneralListener());
		super.onCreate();
	}

	public void onTerminate() {
		// TODO Auto-generated method stub
		if (bMapMan != null) {
			bMapMan.destroy();
			bMapMan = null;
		}
		super.onTerminate();
	}

	static class MyGeneralListener implements MKGeneralListener {
		@Override
		public void onGetNetworkState(int iError) {
			Toast.makeText(BaiduMap.bMapApp.getApplicationContext(), "网络出错！",
					Toast.LENGTH_LONG).show();
		}

		@Override
		public void onGetPermissionState(int iError) {
			if (iError == MKEvent.ERROR_PERMISSION_DENIED) {
				Toast.makeText(BaiduMap.bMapApp.getApplicationContext(),
						"授权Key错误！", Toast.LENGTH_LONG).show();
				BaiduMap.bMapApp.bKeyRight = false;
			}
		}

	}
}
